package com.cyzy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyzy.domin.TAllGood;
import com.cyzy.domin.TAreas;
import com.cyzy.domin.TEvaluations;
import com.cyzy.domin.TGoods;
import com.cyzy.dto.ResponseData;
import com.cyzy.service.TAreasService;
import com.cyzy.mapper.TAreasMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
* @author Liu
* @description 针对表【t_areas(地区表，用于存储地区的名称信息)】的数据库操作Service实现
* @createDate 2024-11-21 10:55:08
 * 我是大帅哥
*/
@Service
public class TAreasServiceImpl extends ServiceImpl<TAreasMapper, TAreas>implements TAreasService{

    @Autowired
    private TAreasMapper tAreasMapper;

    // 查询地址
    //我是大帅哥
    @Override
    public ResponseData findTArea() {
        List<TAreas> tAreas = null;
        try {
            tAreas = tAreasMapper.findTArea();
        }catch (Exception e){
            return ResponseData.no2("查询错误");
        }
        return ResponseData.ok2(tAreas);
    }

    @Override
    public ResponseData findActiveImage(TAreas area) {
        return null;
    }

    @Override
    public ResponseData findMenu(TAreas area) {
        return null;
    }

    @Override
    public ResponseData findHeartProduct(Integer areasId,String goodsName) {
        List<TGoods> tGoods = null;
        try{
            tGoods = tAreasMapper.findHeartProduct(areasId, goodsName);
        }catch (Exception e){
            return ResponseData.no2("查询错误");
        }
        return ResponseData.ok2(tGoods);
    }

    @Override
    public ResponseData findConstProduct(Integer areasId,String goodsName,Integer curr,Integer size) {
        List<TGoods> tGoods = null;
        try{
            if(curr == null || curr == 0){
                curr = 1;
            }
            if (size == null){
                size = 8;
            }
            curr = (curr-1)*size;
            System.out.println("areasId："+areasId+"goodsName："+goodsName+"curr："+curr+"size:"+size);
            tGoods = tAreasMapper.findConstProduct(areasId,goodsName,curr,size);
            System.out.println(tGoods);
            if(tGoods == null || tGoods.isEmpty()){
                return ResponseData.no2("没有多的商品了");
            }
        }catch (Exception e){
            return ResponseData.no2("查询错误");
        }
        return ResponseData.ok2(tGoods);
    }

    @Override
    public ResponseData findConstProduct1(Integer areasId,String goodsName,Integer classifyId) {
        List<TGoods> tGoods = null;
        try{

            System.out.println("areasId："+areasId+"goodsName："+goodsName+"classifyId:"+classifyId);
            String idc = String.valueOf(classifyId);
            tGoods = tAreasMapper.findConstProduct1(areasId,goodsName,idc);
            System.out.println(tGoods);
            if(tGoods == null || tGoods.isEmpty()){
                return ResponseData.no2("没有多的商品了");
            }
        }catch (Exception e){
            System.out.println(e.getMessage());
//            return ResponseData.no2("查询错误");
        }
        return ResponseData.ok2(tGoods);
    }

    // 查询全部信息
    @Override
    public ResponseData findAllGoods(String goodsId) {
        List<TGoods> tGoods = null;
        try{
            tGoods = tAreasMapper.findAllGoods(goodsId);
            System.out.println("TAllGood:" + goodsId);
            if(tGoods == null || tGoods.isEmpty()){
                return ResponseData.no2("没有更多的商品了");
            }
        }catch (Exception e){
            return ResponseData.no2("查询错误");
//            System.out.println(e.getMessage());
        }
        return ResponseData.ok2(tGoods);
    }

    // 查询评论
    @Override
    public ResponseData findaEvalue(String goodsId) {
        //我是大帅哥
        List<TEvaluations> tGoods = null;
        try{

            tGoods = tAreasMapper.findaEvalue(goodsId);
            System.out.println("开始");
            System.out.println("TAllGood:" + tGoods);
            if(tGoods == null || tGoods.isEmpty()){
                return ResponseData.no2("没有更多的商品了");
            }
        }catch (Exception e){
//            return ResponseData.no2("查询错误");
            System.out.println(e.getMessage());
        }
        return ResponseData.ok2(tGoods);
    }
}




